﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace AsyncTaskManager.Converter
{
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var flag = false;
            if (value is bool)
            {
                flag = (bool)value;
            }

            if (parameter != null && bool.Parse(parameter.ToString())) // le paramètre correspond à la négation du test
                return (flag ? Visibility.Collapsed : Visibility.Visible);
            return (flag ? Visibility.Visible : Visibility.Collapsed);

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((value is Visibility) && (((Visibility)value) == Visibility.Visible));
        }
    }
}
